--[[
addEvent("addPaintJobVeh", true)
addEventHandler("addPaintJobVeh", root, function(veh)
for i,v in ipairs(getElementsByType("vehicle")) do
local shaderid = tonumber(getElementData(v,"vehicle:shader"))

if shaderid ~= 0 then
        if shaderid == 1 then
		vehTexture = dxCreateTexture( ":PSSM-painjobs/files/"..shaderid..".png" )
	    shader_cars, tec = dxCreateShader ( ":PSSM-shadery/shader.fx" )
	    engineRemoveShaderFromWorldTexture ( shader_cars, "vehiclegrunge256", v )
	    engineApplyShaderToWorldTexture ( shader_cars, "vehiclegrunge256", v )
     	dxSetShaderValue ( shader_cars, "TX0", vehTexture ) 	
		end
	else
		local shader = dxCreateShader( ":PSSM-shadery/shader.fx" )
		engineApplyShaderToWorldTexture( shader, "vehiclegrunge256", v )
		engineApplyShaderToWorldTexture( shader, "?emap*", v )
	end
end
end)
]]
addEvent("pssm_vehicles:clear", true)
addEventHandler("pssm_vehicles:clear", root, function(veh)
	local shader = dxCreateShader( ":cmta-shadery/shader.fx" )
	engineApplyShaderToWorldTexture( shader, "vehiclegrunge256", veh )
	engineApplyShaderToWorldTexture( shader, "?emap*", veh )

	if getElementData(veh,"vehicle:ownedPlayer") == getElementData(localPlayer,"player:uid") and getElementData(veh,"vehicle:ownedGroup") == "Brak" then
		blip = createBlipAttachedTo(veh,0,2,255,0,0,255,1,99999)
		setElementData(blip,"blip:privveh",true)
	end
	if getElementData(veh,"vehicle:ownedGroup") == getElementData(localPlayer,"player:organization") and (getElementData(veh,"vehicle:ownedPlayer") ~= getElementData(localPlayer,"player:uid")) then
		blip = createBlipAttachedTo(veh,0,2,106,90,205,255,1,99999)
		setElementData(blip,"blip:privveh",true)
	end
	if getElementData(veh,"vehicle:ownedGroup") == getElementData(localPlayer,"player:komis") then
		blip = createBlipAttachedTo(veh,0,2,173,255,47,255,1,99999)
		setElementData(blip,"blip:privveh",true)
	end
	local rent = getElementData(veh,"vehicle:rent")
	if rent and (type(rent) == "table") then
		for i,s in pairs(rent) do
			if tonumber(s) == getElementData(localPlayer,"player:uid") then
				blip = createBlipAttachedTo(veh,0,2.2,255,105,180,255,1,99999)
				setElementData(blip,"blip:privveh",true)
			end
		end
	end

		local shaderid = tonumber(getElementData(veh,"vehicle:shader"))
		if tonumber(shaderid) ~= 0 and getElementData(veh,"vehicle:id") then
				vehTexture = dxCreateTexture( ":cmta-paintjoby/files/"..shaderid..".png" )
				shader_carsstart, tec = dxCreateShader ( ":cmta-shadery/shader.fx" )
				engineRemoveShaderFromWorldTexture ( shader_carsstart, "vehiclegrunge256", veh )
				engineApplyShaderToWorldTexture ( shader_carsstart, "vehiclegrunge256", veh )
				 dxSetShaderValue ( shader_carsstart, "TX0", vehTexture ) 	
		end
end)

function clear()
   for i,v in ipairs(getElementsByType("vehicle")) do
	if getElementData(v,"vehicle:id") or getElementData(v,"vehicle:salon") then
	local shader = dxCreateShader( ":cmta-shadery/shader.fx" )
	engineApplyShaderToWorldTexture( shader, "vehiclegrunge256", v )
	engineApplyShaderToWorldTexture( shader, "?emap*", v )
	end
   end
   for i,v in ipairs(getElementsByType("vehicle")) do
	local shaderid = tonumber(getElementData(v,"vehicle:shader"))
	if tonumber(shaderid) ~= 0 and getElementData(v,"vehicle:id") then
			vehTexture = dxCreateTexture( ":cmta-paintjoby/files/"..shaderid..".png" )
			shader_carsstart, tec = dxCreateShader ( ":cmta-shadery/shader.fx" )
			engineRemoveShaderFromWorldTexture ( shader_carsstart, "vehiclegrunge256", v )
			engineApplyShaderToWorldTexture ( shader_carsstart, "vehiclegrunge256", v )
			 dxSetShaderValue ( shader_carsstart, "TX0", vehTexture ) 	
			end
	end
end
addEventHandler("onClientResourceStart",resourceRoot,clear)

